ftp|http|https Url to hyperlink

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    ftp|http|https Url to hyperlink

    Here is a small piece of code which converts url in a string into a hyperlink:

    PHP Code:
    $str = preg_replace("/((ftp)|(http(s?))\:\/\/(([A-z0-9\?\=\-\:\;\.\@\/]+)))/is",'<a href="\\0">\\0</a>',$str); 
    
    example:
    PHP Code:
    $str = 'http://conding-talk.com is the best coding site.';
    $str = preg_replace("/((ftp)|(http(s?))\:\/\/(([A-z0-9\?\=\-\:\;\.\@\/]+)))/is",'<a href="\\0">\\0</a>',$str);
    echo $str; 
    
    and the output will be:
    Code:
    <a href="http://conding-talk.com">http://conding-talk.com</a> is the best coding site.
    Advertise your mobile site for FREE with AdTwirl


    #2
    Thanks for sharing Gum

    Comment

    Working...
    X